package shopping.dao.impl;

import shopping.bean.OrderAndOrderItem;
import shopping.bean.OrderItem;
import shopping.dao.OrderDao;
import shopping.bean.Order;

import java.util.ArrayList;
import java.util.List;

public class OrderDaoImpl extends BaseDao implements OrderDao {
    @Override
    public int saveOrder(Order order) {
        String sql = "insert into cl_order(`order_id`,`create_time`,`price`,`status`,`admin_id`) values(?,?,?,?,?)";

        return update(sql,order.getOrder_id(),order.getCreate_time(),order.getPrice(),order.getStatus(),order.getAdmin_id());
    }

    @Override
    public ArrayList<Order> selectOrderAll() {
//        String sql = "select c.*,cl.name,cl.count,cl.total_price,adminname,email from cl_order c left join cl_order_item cl on c.order_id = cl.order_id inner join admin on c.admin_id = admin.id";
//        List<OrderAndOrderItem> orderList = queryForList(OrderAndOrderItem.class, sql);

        String sql = "select * from cl_order";
        List<Order> orderList = queryForList(Order.class, sql);

        ArrayList orderLists = new ArrayList<Order>(orderList);
        return orderLists;
    }

    @Override
    public ArrayList<OrderItem> selectOrderItemByOrder_id(String orderId) {
        String sql = "select * from cl_order_item where order_id = ?";
        List<OrderItem> orderList = queryForList(OrderItem.class, sql,orderId);

        ArrayList orderItems = new ArrayList<OrderItem>(orderList);
        return orderItems;
    }
}
